//
//  MPCPageLoadingView.m
//  MPTCustomUILibrary
//
//  Created by macRong on 2017/8/31.
//  Copyright © 2017年 jxzjxz. All rights reserved.
//

#import "MPCPageLoadingView.h"
#import "MPCLoadStatusViewDefines.h"
#import "MPCShimmering.h"
#import "MPCShimmeringView.h"
#import "MPCRotateLoadingView.h"

// 距离centerY向上像素
static const float MPCPageLoadingView_CenterYUPConstraint = 30;


@interface MPCPageLoadingView()
{
    MPCShimmeringView *_shimmeringView;
}

@property (nonatomic, strong) UIView *shineView;
@property (nonatomic, strong) UIView *nonNetView;
@property (nonatomic, strong) UIView *hintNOdataView;
@property (nonatomic, strong) UIView *failedView;
@property (nonatomic, strong) UIView *mbHud;
@property (nonatomic, strong) UIButton *reBtn;

@property (nonatomic, copy) ReAction reActionBlock;
@property (nonatomic, copy) ReAction controlActionBlock;

@end


@implementation MPCPageLoadingView


- (void)dealloc
{
    NSLog(@"%s ✅",__FUNCTION__);
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self)
    {
        // 初始化变量
        [self initVariable];
    }
    
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    
    if (self)
    {
        // 初始化变量
        [self initVariable];
    }
    
    return self;
}

- (void)initVariable
{
    self.backgroundColor = [UIColor whiteColor];
    
    self.centerY = NO;
}


#pragma mark - loading

- (void)showLoadingViewWithImageName:(NSString *)imageName
                      shineImageName:(NSString *)shineImageName
{

    [self removeAllSubView];

    [self addSubview:self.shineView];
    [self.shineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    UIImage *placeHolderImage = [UIImage imageNamed:imageName];
    UIImageView *placeHolderImageView = [[UIImageView alloc]init];
    placeHolderImageView.image = placeHolderImage;
    [self.shineView addSubview:placeHolderImageView];
    
    [placeHolderImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(placeHolderImage.size.width, placeHolderImage.size.height));
        make.center.equalTo(self.shineView);
    }];
    
    
    // --------- shine ---------
    _shimmeringView = [[MPCShimmeringView alloc] init];
    _shimmeringView.shimmering = YES;
//    _shimmeringView.shimmeringBeginFadeDuration = 0.03f;
    _shimmeringView.shimmeringOpacity = 1.0;
    _shimmeringView.shimmeringAnimationOpacity  = 0.f;
    _shimmeringView.shimmeringSpeed = 90;
    _shimmeringView.shimmeringHighlightLength = 0.45f;
    
    [self.shineView addSubview:_shimmeringView];
    
    UIImageView *imgLogoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:shineImageName]];
    imgLogoView.backgroundColor = [UIColor clearColor];
    _shimmeringView.contentView = imgLogoView;
    [_shimmeringView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(placeHolderImageView);
    }];
}


#pragma mark -无网络

- (void)showNonNetViewWithImageName:(NSString *)imageName
                          hintTitle:(nullable NSString *)hintTitle
                        buttonTitle:(NSString *)buttonTitle
                             action:(ReAction)action
{
    [self removeAllSubView];

    [self addSubview:self.nonNetView];
    [self.nonNetView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    // superView
    UIView *supView = [[UIView alloc]init];
    [self.nonNetView addSubview:supView];
    
    // imageView
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
    [supView addSubview:imageView];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(supView.mas_top);
        make.size.mas_equalTo(CGSizeMake(image.size.width, image.size.height));
        make.centerX.equalTo(supView);
    }];
    
    // label
    UILabel *label = [[UILabel alloc]init];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont YXFontOfSize:15.0f];
    label.textColor = MPBConfig.color.c10;
    label.text = hintTitle;
    [supView addSubview:label];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(supView);
        make.top.equalTo(imageView.mas_bottom).offset(0);
        CGFloat height = (hintTitle != nil && hintTitle.length)>0 ? 21 : 0;
        make.height.offset(height);
    }];
    
    CGFloat cornerRadiusWidth = 30.0f;

    // reButton
    UIButton *reBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [reBtn setTitle:buttonTitle forState:UIControlStateNormal];
    [reBtn setTitleColor:MPBConfig.color.c10 forState:UIControlStateNormal];
    reBtn.titleLabel.font = [UIFont YXFontOfSize:14.0f];
    [reBtn addTarget:self action:@selector(reAction:) forControlEvents:UIControlEventTouchUpInside];
    reBtn.layer.cornerRadius = cornerRadiusWidth/2 +2;
    reBtn.layer.masksToBounds = YES;
    reBtn.layer.borderColor = MPBConfig.color.c8.CGColor;
    reBtn.layer.borderWidth = 1;
    [supView addSubview:reBtn];
    CGSize size = CGSizeMake(MAXFLOAT, 32.0f);
    CGSize buttonSize = [buttonTitle boundingRectWithSize:size
                                              options:NSStringDrawingTruncatesLastVisibleLine  | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                           attributes:@{ NSFontAttributeName:reBtn.titleLabel.font}
                                              context:nil].size;
    [reBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(label.mas_bottom).offset(30.0f);
        make.centerX.equalTo(supView);
        make.size.mas_equalTo(CGSizeMake(buttonSize.width+cornerRadiusWidth, 32));
        make.bottom.equalTo(supView.mas_bottom).priorityLow();
    }];
    
    CGFloat height = [supView systemLayoutSizeFittingSize:
                      UILayoutFittingCompressedSize].height;
    
    [supView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.nonNetView);
        
        if (self.centerY)
        {
            make.centerY.equalTo(self.nonNetView.mas_centerY);
        }
        else
        {
            make.centerY.equalTo(self.nonNetView.mas_centerY).multipliedBy(1).offset(-MPCPageLoadingView_CenterYUPConstraint);
        }
        
        make.height.offset(height);
    }];
    
    self.reActionBlock = ^()
    {
        action();
    };
}

- (void)showNonNetViewWithImageName:(NSString *)imageName hintTitle:(NSString *)hintTitle msg:(NSString *)msg buttonTitle:(NSString *)buttonTitle action:(ReAction)action
{
    [self removeAllSubView];
    
    [self addSubview:self.nonNetView];
    [self.nonNetView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    // superView
    UIView *supView = [[UIView alloc]init];
    [self.nonNetView addSubview:supView];
    
    // imageView
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
    [supView addSubview:imageView];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(supView.mas_top);
        make.size.mas_equalTo(CGSizeMake(image.size.width, image.size.height));
        make.centerX.equalTo(supView);
    }];
    
    // label
    UILabel *label = [[UILabel alloc]init];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont YXFontOfSize:24];
    label.textColor = [UIColor YXColorWithHexCode:@"#23232b"];
    label.text = hintTitle;
    [supView addSubview:label];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(supView);
        make.top.equalTo(imageView.mas_bottom).offset(20);
        CGFloat height = (hintTitle != nil && hintTitle.length)>0 ? 24 : 0;
        make.height.offset(height);
    }];
    
    //msg
    UILabel *msgLb = [UILabel new];
    msgLb.text = msg;
    msgLb.font = [UIFont YXFontOfSize:13];
    msgLb.textAlignment = NSTextAlignmentCenter;
    msgLb.textColor = [UIColor YXColorWithHexCode:@"#97979c"];
    [supView addSubview:msgLb];
    
    [msgLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(supView);
        make.top.equalTo(label.mas_bottom).offset(14);
        make.height.mas_equalTo(15);
    }];
    
    // reButton
    UIButton *reBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [reBtn setTitle:buttonTitle forState:UIControlStateNormal];
    [reBtn setTitleColor:[UIColor YXColorWithHexCode:@"#5495FF"] forState:UIControlStateNormal];
    reBtn.titleLabel.font = [UIFont YXFontOfSize:14.0f];
    [reBtn addTarget:self action:@selector(reAction:) forControlEvents:UIControlEventTouchUpInside];
    [supView addSubview:reBtn];
    CGSize size = CGSizeMake(MAXFLOAT, 32.0f);
    CGSize buttonSize = [buttonTitle boundingRectWithSize:size
                                                  options:NSStringDrawingTruncatesLastVisibleLine  | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                               attributes:@{ NSFontAttributeName:reBtn.titleLabel.font}
                                                  context:nil].size;
    [reBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(msgLb.mas_bottom).offset(30.0f);
        make.centerX.equalTo(supView);
        make.size.mas_equalTo(CGSizeMake(buttonSize.width, 32));
        make.bottom.equalTo(supView.mas_bottom).priorityLow();
    }];
    
    CGFloat height = [supView systemLayoutSizeFittingSize:
                      UILayoutFittingCompressedSize].height;
    
    [supView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.nonNetView);
        
        if (self.centerY)
        {
            make.centerY.equalTo(self.nonNetView.mas_centerY);
        }
        else
        {
            make.centerY.equalTo(self.nonNetView.mas_centerY).multipliedBy(1).offset(-MPCPageLoadingView_CenterYUPConstraint);
        }
        
        make.height.offset(height);
    }];
    
    self.reActionBlock = ^()
    {
        action();
    };
}


#pragma makr - 加载失败

- (void)showFailViewWithHintTitle:(nullable NSString *)hintTitle
                      buttonTitle:(NSString *)buttonTitle
                           action:(ReAction)action
{
    [self removeAllSubView];

    [self addSubview:self.failedView];
    [self.failedView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    // superView
    UIView *supView = [[UIView alloc]init];
    [self.failedView addSubview:supView];

    // label
    UILabel *label = [[UILabel alloc]init];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont YXFontOfSize:18.0f];
    label.textColor = MPBConfig.color.c11;
    label.text = hintTitle;
    [supView addSubview:label];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(supView);
        make.top.equalTo(supView.mas_top);
        CGFloat height = (hintTitle != nil && hintTitle.length)>0 ? 30 : 0;
        make.height.offset(height);
    }];
    
    CGFloat cornerRadiusWidth = 30.0f;

    // reButton
    UIButton *reBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [reBtn setTitle:buttonTitle forState:UIControlStateNormal];
    [reBtn setTitleColor:MPBConfig.color.c10 forState:UIControlStateNormal];
    reBtn.titleLabel.font = [UIFont YXFontOfSize:13.0f];
    [reBtn addTarget:self action:@selector(reAction:) forControlEvents:UIControlEventTouchUpInside];
    reBtn.layer.cornerRadius = cornerRadiusWidth/2 +2;
    reBtn.layer.masksToBounds = YES;
    reBtn.layer.borderColor = MPBConfig.color.c8.CGColor;
    reBtn.layer.borderWidth = 1;
    [supView addSubview:reBtn];
    CGSize size = CGSizeMake(MAXFLOAT, 32.0f);
    CGSize buttonSize = [buttonTitle boundingRectWithSize:size
                                                  options:NSStringDrawingTruncatesLastVisibleLine  | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                               attributes:@{ NSFontAttributeName:reBtn.titleLabel.font}
                                                  context:nil].size;
    [reBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(label.mas_bottom).offset(8);
        make.centerX.equalTo(supView);
        make.size.mas_equalTo(CGSizeMake(buttonSize.width+cornerRadiusWidth, 32));
        make.bottom.equalTo(supView.mas_bottom).priorityLow();
    }];
    
    CGFloat height = [supView systemLayoutSizeFittingSize:
                      UILayoutFittingCompressedSize].height;
    
    [supView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.failedView);

        if (self.centerY)
        {
            make.centerY.equalTo(self.failedView.mas_centerY);
        }
        else
        {
            make.centerY.equalTo(self.failedView.mas_centerY).multipliedBy(1).offset(-MPCPageLoadingView_CenterYUPConstraint);
        }
        
        make.height.offset(height);
    }];
    
    self.reActionBlock = ^()
    {
        action();
    };
}


#pragma makr - 无数据

- (void)showNotDataViewWithImageName:(NSString *)imageName
                        hintTitle:(nullable NSString *)hintTitle
                           action:(ReAction)action
{
    [self removeAllSubView];
    
    [self addSubview:self.nonNetView];
    [self.nonNetView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    // superView
    UIView *supView = [[UIView alloc]init];
    [self.nonNetView addSubview:supView];
    
    // imageView
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
    [supView addSubview:imageView];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(supView.mas_top);
        make.size.mas_equalTo(CGSizeMake(image.size.width, image.size.height));
        make.centerX.equalTo(supView);
    }];
    
    // label
    UILabel *label = [[UILabel alloc]init];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont YXFontOfSize:15.0f];
    label.textColor = MPBConfig.color.c10;
    label.text = hintTitle;
    [supView addSubview:label];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.nonNetView);
        make.top.equalTo(imageView.mas_bottom).offset(0);
        CGFloat height = (hintTitle != nil && hintTitle.length)>0 ? 21 : 0;
        make.height.offset(height);
        make.bottom.equalTo(supView.mas_bottom).priorityLow();
    }];
    
    // control
    UIControl *control = [[UIControl alloc]init];
    control.backgroundColor = [UIColor clearColor];
    [control addTarget:self action:@selector(controlAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:control];
    
    [control mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    self.controlActionBlock = ^{
        action();
    };
    
    CGFloat height = [supView systemLayoutSizeFittingSize:
                      UILayoutFittingCompressedSize].height;
    
    [supView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.nonNetView);

        if (self.centerY)
        {
            make.centerY.equalTo(self.nonNetView.mas_centerY);
        }
        else
        {
            make.centerY.equalTo(self.nonNetView.mas_centerY).multipliedBy(1).offset(-MPCPageLoadingView_CenterYUPConstraint);
        }
        
        make.height.offset(height);
    }];
}

- (void)showNotDataViewWithImageName:(NSString *)imageName
                           hintTitle:(nullable NSString *)hintTitle
                            subTitle:(nullable NSString *)subTitle
                              action:(ReAction)action
{
    [self removeAllSubView];
    
    [self addSubview:self.nonNetView];
    [self.nonNetView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    // superView
    UIView *supView = [[UIView alloc]init];
    [self.nonNetView addSubview:supView];
    
    // imageView
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
    [supView addSubview:imageView];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(supView.mas_top).offset(-63);
        make.size.mas_equalTo(CGSizeMake(image.size.width, image.size.height));
        make.centerX.equalTo(supView);
    }];
    
    // label
    UILabel *label = [[UILabel alloc]init];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont YXRegularFontOdSize:20.0f];
    label.textColor = MPBConfig.color.c12;
    label.text = hintTitle;
    [supView addSubview:label];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.nonNetView);
        make.top.equalTo(imageView.mas_bottom).offset(20);
        CGFloat height = (hintTitle != nil && hintTitle.length)>0 ? 25 : 0;
        make.height.offset(height);
        make.bottom.equalTo(supView.mas_bottom).priorityLow();
    }];
    
    // subTitle
    UILabel *labelSub = [[UILabel alloc]init];
    labelSub.textAlignment = NSTextAlignmentCenter;
    labelSub.font = [UIFont YXFontOfSize:15.0f];
    labelSub.textColor = MPBConfig.color.c10;
    labelSub.text = subTitle;
    [supView addSubview:labelSub];
    
    [labelSub mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.nonNetView);
        make.top.equalTo(label.mas_bottom).offset(7);
        CGFloat height = (subTitle != nil && subTitle.length)>0 ? 21 : 0;
        make.height.offset(height);
        make.bottom.equalTo(supView.mas_bottom).priorityLow();
    }];
    
    // control
    UIControl *control = [[UIControl alloc]init];
    control.backgroundColor = [UIColor clearColor];
    [control addTarget:self action:@selector(controlAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:control];
    
    [control mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    self.controlActionBlock = ^{
        action();
    };
    
    CGFloat height = [supView systemLayoutSizeFittingSize:
                      UILayoutFittingCompressedSize].height;
    
    [supView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.nonNetView);
        
        if (self.centerY)
        {
            make.centerY.equalTo(self.nonNetView.mas_centerY);
        }
        else
        {
            make.centerY.equalTo(self.nonNetView.mas_centerY).multipliedBy(1).offset(-MPCPageLoadingView_CenterYUPConstraint);
        }
        
        make.height.offset(height);
    }];
}

- (void)showNotDataViewWithHintTitle:(nullable NSString *)hintTitle
                              action:(ReAction)action
{
    [self removeAllSubView];
    
    [self addSubview:self.nonNetView];
    [self.nonNetView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    // superView
    UIView *supView = [[UIView alloc]init];
    [self.nonNetView addSubview:supView];
    
    // label
    UILabel *label = [[UILabel alloc]init];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont YXFontOfSize:15.0f];
    label.textColor = MPBConfig.color.c10;
    label.text = hintTitle;
    [supView addSubview:label];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.nonNetView);
        make.top.equalTo(self.mas_centerY).offset(-10);
        CGFloat height = (hintTitle != nil && hintTitle.length)>0 ? 21 : 0;
        make.height.offset(height);
        make.bottom.equalTo(supView.mas_bottom).priorityLow();
    }];
    
    // control
    UIControl *control = [[UIControl alloc]init];
    control.backgroundColor = [UIColor clearColor];
    [control addTarget:self action:@selector(controlAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:control];
    
    [control mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    self.controlActionBlock = ^{
        action();
    };
    
    CGFloat height = [supView systemLayoutSizeFittingSize:
                      UILayoutFittingCompressedSize].height;
    
    [supView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.nonNetView);
        
        if (self.centerY)
        {
            make.centerY.equalTo(self.nonNetView.mas_centerY);
        }
        else
        {
            make.centerY.equalTo(self.nonNetView.mas_centerY).multipliedBy(1).offset(-MPCPageLoadingView_CenterYUPConstraint);
        }
        
        make.height.offset(height);
    }];
}


#pragma mark - Hud

- (void)showHudWithImageName:(NSString *)imageName
                       title:(nullable NSString *)hintTitle
{
    [self removeAllSubView];
    
    [self addSubview:self.mbHud];
    [self.mbHud mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];

    if (imageName.length == 0)
    {
        return;
    }
    
    // Hud
    UIView *tempHud = [[UIView alloc]init];
    tempHud.frame = CGRectMake(0, 0, 30, 30);
    
    UIImage *image = [UIImage imageNamed:imageName];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:tempHud animated:YES];
    MPCRotateLoadingView *rotateLoadingview = [[MPCRotateLoadingView alloc] initWithFrame:CGRectMake(0.0f, 0.0, 30.0f, 30.0f)];
    rotateLoadingview.rotateImage = image;
    [rotateLoadingview startAnimating];
    hud.customView = rotateLoadingview;
    hud.color = [UIColor clearColor];
    hud.mode = MBProgressHUDModeCustomView;
    hud.labelText = hintTitle;
    hud.labelFont = [UIFont YXFontOfSize:13.0f];
    hud.labelColor = MPBConfig.color.c10;
    hud.margin = 10;
    hud.center = self.mbHud.center;
    
    [self.mbHud addSubview:hud];
}


#pragma mark - 重试按钮

- (void)showRetryButton:(NSString *)buttonTitle
                 action:(ReAction)action
{
    [self removeAllSubView];

    CGFloat cornerRadiusWidth = 30.0f;
    
    // reButton
    self.reBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.reBtn setTitle:buttonTitle forState:UIControlStateNormal];
    [self.reBtn setTitleColor:MPBConfig.color.c10 forState:UIControlStateNormal];
    self.reBtn.titleLabel.font = [UIFont YXFontOfSize:13.0f];
    [self.reBtn addTarget:self action:@selector(reAction:) forControlEvents:UIControlEventTouchUpInside];
    self.reBtn.layer.cornerRadius = cornerRadiusWidth/2+2;
    self.reBtn.layer.masksToBounds = YES;
    self.reBtn.layer.borderColor = MPBConfig.color.c8.CGColor;
    self.reBtn.layer.borderWidth = 1;
    [self addSubview:self.reBtn];
    CGSize size = CGSizeMake(MAXFLOAT, 32.0f);
    CGSize buttonSize = [buttonTitle boundingRectWithSize:size
                                                  options:NSStringDrawingTruncatesLastVisibleLine  | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                               attributes:@{ NSFontAttributeName:self.reBtn.titleLabel.font}
                                                  context:nil].size;
    [self.reBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        
        if (self.centerY)
        {
            make.centerY.equalTo(self.mas_centerY);
        }
        else
        {
            make.centerY.equalTo(self.mas_centerY).multipliedBy(1).offset(-MPCPageLoadingView_CenterYUPConstraint);
        }
        
        make.size.mas_equalTo(CGSizeMake(buttonSize.width+cornerRadiusWidth, 32));
    }];
    
    
    self.reActionBlock = ^()
    {
        action();
    };
}

- (void)removeAllSubView
{
    if (_shineView)
    {
        [self.shineView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    }
    
    if (_nonNetView)
    {
        [self.nonNetView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    }
    
    if (_hintNOdataView)
    {
        [self.hintNOdataView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    }
    
    if (_failedView)
    {
        [self.failedView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    }
    
    if (_mbHud)
    {
        [self.mbHud.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    }
    
    if (self.reBtn)
    {
        [self.reBtn removeFromSuperview];
    }
}

- (void)removePageLoadingView
{
    _shimmeringView.shimmering = !_shimmeringView.shimmering;
    
    [UIView animateWithDuration:0.6
                     animations:^{
                         self.alpha = 0;
                     }
                     completion:^(BOOL finished){
                         [self removeFromSuperview];
                     }];
}


- (void)reAction:(UIButton *)btn
{
    if (self.reActionBlock)
    {
        self.reActionBlock();
    }
}

- (void)controlAction:(UIControl *)cont
{
    if (self.controlActionBlock)
    {
        self.controlActionBlock();
    }
}

- (void)willMoveToSuperview:(UIView *)newSuperview
{
    [super willMoveToSuperview:newSuperview];
    
    self.alpha = 1;
    self.backgroundColor = [UIColor whiteColor];
    
    NSLog(@"%s",__FUNCTION__);
}


#pragma mark - Setter/Getter

- (UIView *)shineView
{
    if (!_shineView)
    {
        _shineView = [[UIView alloc]init];
        _shineView.backgroundColor = [UIColor clearColor];
    }
    
    return _shineView;
}

- (UIView *)nonNetView
{
    if (!_nonNetView)
    {
        _nonNetView = [[UIView alloc]init];
        _nonNetView.backgroundColor = [UIColor clearColor];
    }
    
    return _nonNetView;
}

- (UIView *)hintNOdataView
{
    if (!_hintNOdataView)
    {
        _hintNOdataView = [[UIView alloc]init];
        _hintNOdataView.backgroundColor = [UIColor clearColor];
    }
    
    return _hintNOdataView;
}

- (UIView *)failedView
{
    if (!_failedView)
    {
        _failedView = [[UIView alloc]init];
        _failedView.backgroundColor = [UIColor clearColor];
    }
    
    return _failedView;
}

- (UIView *)mbHud
{
    if (!_mbHud)
    {
        _mbHud = [[UIView alloc]init];
        _mbHud.backgroundColor = [UIColor clearColor];
    }
    
    return _mbHud;
}


@end
